﻿@model Log
@Html.Extra()
@{
    Layout = "~/Views/Shared/OA/_Detail.cshtml";

    var operation = (Operation)Model.Operation;

    var properties = SerializationHelper.JsonDeserialize<JObject>(Model.LogType.Config).Properties();
    var oldValue = SerializationHelper.JsonDeserialize<JObject>(Model.OldValue);
    var newValue = SerializationHelper.JsonDeserialize<JObject>(Model.NewValue);
}
@section Toolbar
{
    @Html.MyNet().Button(new ButtonOptions { Text = "返回", Click = "back" })
}
@section Main
{
    <fieldset>
        <legend>基本信息</legend>
        <table>
            <colgroup>
                <col style="width: 150px;" />
            </colgroup>
            <tr>
                <th>业务：</th>
                <td>
                    @Model.LogType.Name
                </td>
            </tr>
            <tr>
                <th>操作：</th>
                <td>
                    @(operation.ToText())
                </td>
            </tr>
            <tr>
                <th>操作人：</th>
                <td>
                    @Model.CreatorUserName
                </td>
            </tr>
            <tr>
                <th>操作人IP：</th>
                <td>
                    @Model.IP
                </td>
            </tr>
            <tr>
                <th>操作时间：</th>
                <td>
                    @Model.CreateTime
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <legend>数据信息</legend>
        @if (string.IsNullOrEmpty(Model.LogType.View))
        {
            <table>
                <colgroup>
                    <col style="width: 150px;" />
                </colgroup>
                <tr>
                    <th style="font-weight: bold;">字段：</th>
                    @switch (operation)
                    {

                        case Operation.Modify:
                        <td style="font-weight: bold;">旧值</td>
                        <td style="font-weight: bold;">新值</td>
                            break;
                        case Operation.Create:
                        case Operation.Remove:
                        <td style="font-weight: bold;">值</td>
                            break;
                        default:
                            break;
                    }

                </tr>
                @foreach (var propertie in properties)
                {
                    var newData = newValue == null ? string.Empty : newValue.Value<object>(propertie.Name);
                    var oldData = oldValue == null ? string.Empty : oldValue.Value<object>(propertie.Name);

                    switch (operation)
                    {
                        case Operation.Create:
                    <tr>
                        <th>
                            @propertie.Value：
                        </th>
                        <td>
                            @newData
                        </td>
                    </tr>
                            break;
                        case Operation.Modify: 
                    <tr  @Html.Raw(oldData.ToString().Equals(newData.ToString()) ? "" : "style='color: red;'")>
                        <th>
                            @propertie.Value：
                        </th>
                        <td>
                            @oldData
                        </td>
                        <td>
                            @newData
                        </td>
                    </tr> 
                            break;
                        case Operation.Remove:
                    <tr>
                        <th>
                            @propertie.Value：
                        </th>
                        <td>
                            @oldData
                        </td>
                    </tr>
                            break;
                        default:
                    <tr>
                        <td></td>
                    </tr>
                            break;
                    }
                }
            </table>

        }
        else
        {
            @Html.Partial(Model.LogType.View)
        }
    </fieldset>

}

